<template>
	<view class="page" ref="page">
		<!-- 搜索 -->
		
		<!-- 分类数据 -->
		<view class="classify-data">
			<view class="classify-one">
				<scroll-view scroll-y class="classify-list">
					<view v-for="(item,index) in fenlei" :key="index" :class="tabs==item.id?'list action':'list'" @click="tab(item)">
						<text>{{item.name}}</text>
					</view>
				</scroll-view>
			</view>
			<view class="classify-two-three">
				<scroll-view scroll-y class="scroll">
					<view class="classify-two" v-for="(item,index) in cate" :key="index">
						<view class="two-name" v-if="item.goods.length!=0">
							<view class="name ">{{item.name}}</view>
						</view>
						<view class="classify-three">
							<view class="list" v-for="(itm,inx) in item.goods" :key="inx" @click="go_url(itm)" v-if="item.goods.length!=0">
								<tui-image mode="aspectFill" width="100%" height="250rpx" :src="itm.cover"> </tui-image>
								<text class="two-omit">{{itm.name}}</text>
								<!-- <view class="red" v-if="itm.area_type==3">{{itm.price_selling}}积分</view> -->
								<view class="red">{{itm.price_selling}}</view>
							</view>
							
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<tui-login :show="show"  @close="guanbi"></tui-login>
		<!-- tabbar -->
		<TabBar :tabBarShow="1"></TabBar>
		<tui-img :show="zhiboShow" @finish='endjie'></tui-img>
	</view>
</template>

<script>
	import TabBar from '../../components/TabBar/TabBar.vue';
	export default {
		components: {
			TabBar,
		},
		data() {
			return {
				height: 0,
				fenlei:[],
				cate:[],
				tabs:0,
				show:false,
				isLogin:false,
				zhiboShow:false,
			};
		},
		onReady() {
			setTimeout(() => {
				uni.hideTabBar()
			}, 100)
			let info = uni.createSelectorQuery().select(".page");
			info.boundingClientRect((data) => { //data - 各种参数
				console.log(data.height);
				this.height = data.height - 100;
				// #ifdef APP-PLUS 
				this.height = data.height - 130;
				// #endif 

			}).exec()
		},
		onLoad() {
			
		},
		onShow() {
			let that = this
			that.isLogin = this.tui.isLogin()
			uni.$off('isShow');
			uni.$off('isLogin');
			uni.$off('fcNotic');
			uni.$on('isShow', function(data) {
				that.show = true
			});
			uni.$on('fcNotic', function(data) {
				that.zhiboShow = data
			});
			uni.$on('isLogin', function(data) {
				that.isLogin = this.tui.isLogin()
				that.tui.wxShare()
			});
			that.getList()
			if(that.isLogin){
				that.tui.zhiboList(1)
				that.tui.wxShare()
				
			}
		},
		// #ifdef MP
		onShareAppMessage() {
			return {
				title:'分享海报',
				path:'/pages/home/home?inviter_code='+uni.getStorageSync('inviter_code'),
			};
		},
		// #endif
		onUnload() {
			/** 这里只保留最新的15条会话记录，以保证初次加载性能 */
			uni.$off('isShow');
			uni.$off('isLogin');
			uni.$off('fcNotic');
		},
		methods: {
			guanbi(){
				this.show = false
			},
			endjie(e){
				this.zhiboShow = e
			},
			getList(){
				let that = this
				that.tui.request('api.data/category', "post", {}, false, true, false).then((res) => {
					console.log(res)
					if(res.code==1){
						that.fenlei = res.data.list
						that.cate = that.fenlei[0].cate
						that.tabs = that.fenlei[0].id
					}
					
				}).catch((res) => {
					console.log(res)
				})
			},
			tab(e){
				this.tabs = e.id
				this.cate = e.cate
			},
			/**
			 * 扫一扫点击
			 */
			onCode() {
				// 只允许通过相机扫码
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			},
			/**
			 * 付款码点击
			 */
			go_url(e){
				if(this.tui.isLogin()){
					this.tui.href('/pages/GoodsDetails/GoodsDetails?id='+e.code)
				}else{
					// this.tui.wetLogin()
					setTimeout(function(){
						uni.redirectTo({
							url: '/pages/login/login'
						})
					},1000)
				}
				
			},
			
		}
	}
</script>

<style scoped lang="scss">
	@import 'classify.scss'
</style>
